/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_equipment_management_func.c
	
	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	kenny.weng		2012/7/16	Create
*/

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include "omci_adpt_common.h"
#include "omci_adpt_general.h"
#include "omci_lib_internal.h"

/*******************************************************************************************************************************
9.1.1 ONU-G

********************************************************************************************************************************/
static attribute_func_t ONUGOpStateFunc = {
	getONUGOpStateValue,
	NULL,
};

#ifdef TCSUPPORT_CUC
static attribute_func_t ONUGGetLOID = {
	getONUGLOID,
	NULL,
};

static attribute_func_t ONUGGetLOIDPWD = {
	getONUGLOIDPWD,
	NULL,
};
#else
#define ONUGGetLOID     generalAttrFunc
#define ONUGGetLOIDPWD  generalAttrFunc
#endif

omci_attr_dscp_t omci_attr_onu_g_op[]={
{0, "meId" , 					2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{1, "Vendor id" , 				4 ,     ATTR_ACCESS_R,      ATTR_FORMAT_STRING,           ATTR_FULLY_SUPPORT,&generalAttrFunc},
{2, "Version" , 				14 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,           ATTR_FULLY_SUPPORT,&generalAttrFunc},
{3, "Serial number" , 			8 ,     ATTR_ACCESS_R,      ATTR_FORMAT_STRING,           ATTR_FULLY_SUPPORT,&generalAttrFunc},
{4, "TM option" , 				1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_ENUM,             ATTR_FULLY_SUPPORT,&generalAttrFunc},
{5, "Deprecated" , 				1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{6, "Battery backup" ,			1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{7, "Administrative state" ,	1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{8, "Operational state" ,		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&ONUGOpStateFunc},
{9, "ONU survival time" ,		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{10, "Logical ONU ID" ,			24 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,           ATTR_FULLY_SUPPORT,&ONUGGetLOID},
{11, "Logical password" ,		12 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,           ATTR_FULLY_SUPPORT,&ONUGGetLOIDPWD},
{12, "Credentials status" ,		1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_ENUM,             ATTR_FULLY_SUPPORT,&generalAttrFunc},	
{13, "Extended TC-layer" ,		2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_BIT_FIELD,        ATTR_FULLY_SUPPORT,&generalAttrFunc},
{255, "" , 						0 , 	0 , 0 , 0 , NULL}	
};
omci_me_func_t omci_me_onu_g_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
	omci_me_onu_g_test_result_op,
};

omci_onu_g_t omci_onu_g_attr_data = {0};

omci_attr_t omci_onu_g_attr ={
	(uint8_t *)&omci_onu_g_attr_data,
	sizeof(omci_onu_g_attr_data),
};

/*******************************************************************************************************************************
9.1.2 ONU2-G

********************************************************************************************************************************/
static attribute_func_t OMCCVersionFunc = {
	getOMCCVersionValue,
	NULL,
};
static attribute_func_t SysUpTimeFunc = {
	getSysUpTimeValue,
	NULL,
};

static attribute_func_t SecurityModeFunc = {
	NULL,
	setSecurityModeValue,
};
omci_attr_dscp_t omci_attr_onu2_g_op[]={
{0, "meId" , 					2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{1, "Equipment id" , 			20 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,&generalAttrFunc},
{2, "OMCC version" , 			1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_ENUM,            ATTR_FULLY_SUPPORT,&OMCCVersionFunc},
{3, "Vendor product code" , 	2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{4, "Security capability" , 	1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_ENUM,            ATTR_FULLY_SUPPORT,&generalAttrFunc},
{5, "Security mode" , 			1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_ENUM,            ATTR_FULLY_SUPPORT,&SecurityModeFunc},
{6, "Total priority queue" ,	2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{7, "Total traffic scheduler" ,	1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{8, "Deprecated" ,				1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{9, "Total GEM port-ID" ,		2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{10, "SysUpTime" ,				4 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&SysUpTimeFunc},
{11, "Connectivity capability" ,2,      ATTR_ACCESS_R,      ATTR_FORMAT_BIT_FIELD,       ATTR_FULLY_SUPPORT,&generalAttrFunc},
{12, "Connectivity mode" ,		1,      ATTR_ACCESS_R_W,    ATTR_FORMAT_BIT_FIELD,       ATTR_FULLY_SUPPORT,&generalAttrFunc},
{13, "QoS configuration" ,		2,      ATTR_ACCESS_R,      ATTR_FORMAT_BIT_FIELD,       ATTR_FULLY_SUPPORT,&generalAttrFunc},
{14, "PQ scale factor" ,		2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{255, "" , 						0 , 	0 , 0 , 0 , NULL}
};
omci_me_func_t omci_me_onu2_g_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_onu2_g_t omci_onu2_g_attr_data = {0};

omci_attr_t omci_onu2_g_attr ={
	(uint8_t *)&omci_onu2_g_attr_data,
	sizeof(omci_onu2_g_attr_data),
};

/*******************************************************************************************************************************
9.1.3 ONU data

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_onu_data_op[]={
{0, "meId" , 			2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,&generalAttrFunc},
{1, "MIB data sync" , 	1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,&generalAttrFunc},
{255, "" , 				0 , 	0 , 0 , 0 , NULL}
};
omci_me_func_t omci_me_onu_data_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_onu_data_t omci_onu_data_attr_data = {0};

omci_attr_t omci_onu_data_attr ={
	(uint8_t *)&omci_onu_data_attr_data,
	sizeof(omci_onu_data_attr_data),
};

/*******************************************************************************************************************************
9.1.4 Software image

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_sw_image_op[]={
{0, "meId" , 				2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{1, "Version" , 			14 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,&generalAttrFunc},
{2, "Is committed" , 		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{3, "Is active" , 			1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{4, "Is valid" , 			1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{5, "Product code" , 		25 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_UNSUPPORT,	&generalAttrFunc},
{6, "Image hash" , 			16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,   		 ATTR_UNSUPPORT,	&generalAttrFunc},
{255, "" , 					0 , 	0 , 0 , 0 , NULL}
};

omci_me_func_t omci_me_sw_image_op ={
	NULL,
	NULL,
	NULL,
	omci_me_general_get_op,
	NULL,
	NULL,
};

omci_software_image_t omci_sw_image_attr_data = {0};

omci_attr_t omci_sw_image_attr ={
	(uint8_t *)&omci_sw_image_attr_data,
	sizeof(omci_sw_image_attr_data),
};

/*******************************************************************************************************************************
9.1.5 Cardholder

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_card_holder_op[]={
{0, "meId" , 					2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{1, "Actual unit type" , 		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{2, "Expected unit type" ,		1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{3, "Expected port count" ,		1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
{4, "Expected equipment id" ,	20 ,    ATTR_ACCESS_R_W,    ATTR_FORMAT_STRING,           ATTR_FULLY_SUPPORT,&generalAttrFunc},
{5, "Actual equipment id" ,		20 ,    ATTR_ACCESS_R_W,    ATTR_FORMAT_STRING,           ATTR_FULLY_SUPPORT,&generalAttrFunc},
{6, "Protection pointer" ,		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,     ATTR_FULLY_SUPPORT,&generalAttrFunc},
#ifdef TCSUPPORT_PON_ROSTELECOM
{7, "Protection switch" ,		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_ENUM,            ATTR_FULLY_SUPPORT,&generalAttrFunc},
{8, "ARC" ,						1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{9, "ARC interval" ,			1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
#else
{7, "Protection switch" ,		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_ENUM,            ATTR_UNSUPPORT,NULL},
{8, "ARC" ,						1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_UNSUPPORT,NULL},
{9, "ARC interval" ,			1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_UNSUPPORT,NULL},
#endif
{255, "" , 						0 , 	0 ,0 ,0 ,NULL}
};

omci_me_func_t omci_me_card_holder_op ={
	NULL,
	NULL,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
	NULL
};

omci_cardholder_t omci_card_holder_attr_data = {0};

omci_attr_t omci_card_holder_attr ={
	(uint8_t *)&omci_card_holder_attr_data,
	sizeof(omci_card_holder_attr_data),
};


/*******************************************************************************************************************************
9.1.6 Circuit pack

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_circuit_pack_op[]={
{0, "meId" , 					2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{1, "Type" , 					1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{2, "Number of ports" ,			1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{3, "Serial number" ,			8 ,     ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,&generalAttrFunc},
{4, "Version" ,					14 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,&generalAttrFunc},
{5, "Vendor id" ,				4 ,     ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,&generalAttrFunc},
{6, "Administrative state" ,	1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{7, "Operational state" ,		1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{8, "Bridged or IP ind" ,		1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{9, "Equipment id" ,			20 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,&generalAttrFunc},
{10, "Card configuration" ,		1 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{11, "Total T-CONT buffer" ,	1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{12, "Total priority queue" ,	1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{13, "Total traffic scheduler",	1 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,&generalAttrFunc},
{14, "Power shed override" ,	4 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_BIT_FIELD,       ATTR_FULLY_SUPPORT,&generalAttrFunc},
{255, "" , 						0 , 	0 , 0 , 0 , NULL}
};

omci_me_func_t omci_me_circuit_pack_op ={
	NULL,
	NULL,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
	NULL
};

omci_circuit_pack_t omci_circuit_pack_attr_data = {0};

omci_attr_t omci_circuit_pack_attr ={
	(uint8_t *)&omci_circuit_pack_attr_data,
	sizeof(omci_circuit_pack_attr_data),
};
/*******************************************************************************************************************************
9.1.7 ONU power shedding

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_onu_power_schedding_op[]={
{0, "meId" , 							2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{1, "Restore power timer reset" , 		2,      ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{2, "Data class shedding" , 			2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{4, "Voice class shedding" , 			2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{5, "Video overlay class shedding",		2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{6, "Video return class shedding",		2,      ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{7, "DSL class shedding" , 				2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{8, "ATM class shedding " , 			2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{9, "CES class shedding" , 				2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{10, "Frame class shedding" , 			2 ,     ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{11, "Sdh-sonet class shedding",		2,      ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{12, "Shedding status",					2,      ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT, &generalAttrFunc},
{255, "" ,								0 , 	0 , 0 , 0 , NULL}
};

omci_me_func_t omci_me_onu_power_schedding_op ={
	NULL,
	NULL,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
	NULL
};

omci_onu_power_shedding_t omci_onu_power_schedding_attr_data = {0};

omci_attr_t omci_onu_power_schedding_attr ={
	(uint8_t *)&omci_onu_power_schedding_attr_data,
	sizeof(omci_onu_power_schedding_attr_data),
};

/*******************************************************************************************************************************
9.1.8 Port mapping package 

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_port_mapping_pkt_op[]={
{0, "meId" , 				2 ,     ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT, &generalAttrFunc},
{1, "Max ports" , 			1,      ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT, &generalAttrFunc},
{2, "Port list 1" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{3, "Port list 2" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{4, "Port list 3" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{5, "Port list 4" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{6, "Port list 5" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{7, "Port list 6" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{8, "Port list 7" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{9, "Port list 8" , 		16 ,    ATTR_ACCESS_R,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT, &generalAttrFunc},
{10, "Combined port table",	25,     ATTR_ACCESS_R,      ATTR_FORMAT_TABLE,           ATTR_UNSUPPORT, NULL},
{255, "" , 					0,	 0,	0,	0,	NULL}
};

omci_me_func_t omci_me_port_mapping_pkt_op ={
	NULL,
	NULL,
	NULL,
	omci_me_general_get_op,
	NULL,
	NULL
};

omci_port_mapping_pkt_t omci_port_mapping_pkt_attr_data = {0};

omci_attr_t omci_port_mapping_pkt_attr ={
	(uint8_t *)&omci_port_mapping_pkt_attr_data,
	sizeof(omci_port_mapping_pkt_attr_data),
};


/*******************************************************************************************************************************
9.1.12 ONU remote debug

********************************************************************************************************************************/
static attribute_func_t remoteDebugCmdFunc = {
	NULL,
	setRemoteDebugCmd,
};
static attribute_func_t remoteDebugReplyTabFunc = {
	getRemoteDebugReplyTab, 
	NULL,
};
omci_attr_dscp_t omci_attr_onu_remote_debug_op[]={
{0, "meId" , 				2 ,   ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,	&generalAttrFunc},
{1, "Command format" , 		1 ,   ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,	&generalAttrFunc},
{2, "Command" , 			25 ,  ATTR_ACCESS_W,      ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,	&remoteDebugCmdFunc},
{3, "Reply table" , 		1 ,   ATTR_ACCESS_R,      ATTR_FORMAT_TABLE,           ATTR_FULLY_SUPPORT,	&remoteDebugReplyTabFunc},
{255, "" , 					0 , 	0 ,0 ,0 ,NULL}
};

omci_me_func_t omci_me_onu_remote_debug_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_onu_remote_debug_t omci_onu_remote_debug_attr_data = {0};

omci_attr_t omci_onu_remote_debug_attr ={
	(uint8_t *)&omci_onu_remote_debug_attr_data,
	sizeof(omci_onu_remote_debug_attr_data),
};

/**********************functions implement****************************/
//9.1.1 ONU-G
int getONUGOpStateValue(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{
	

#ifdef BSP_BUILD
	/*Node "GPON_ONU" without attribute "OperationalState"!*/
#else
    omci_onu_g_ptr onu_g_ptr=NULL;
	char tempBuffer[25] = {0};
	
	if(new_info == NULL ||	new_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}

	omci_tcapi_nget("GPON_ONU", "OperationalState", tempBuffer, sizeof(tempBuffer));

	onu_g_ptr = (omci_onu_g_ptr)(new_info->attributes);
	//memcpy(&(onu_g_ptr->operationalState),tempBuffer,omci_attr->attriLen);
	onu_g_ptr->operationalState = (uint8_t)(*tempBuffer);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s] OperationalState = %d\n",__FUNCTION__,onu_g_ptr->operationalState);
#endif
	return 0;
}

int getONUGLOID(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{
	omci_onu_g_ptr onu_g_ptr=NULL;
	char buf[25]={0};
	
	if(new_info == NULL ||	new_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}
	
	onu_g_ptr = (omci_onu_g_ptr)(new_info->attributes);
	omci_lib_get_loid(buf,OMCI_LOID_LENS);
	memcpy(onu_g_ptr->logicalOnuId, buf, 24);
	
	return 0;	
}
int getONUGLOIDPWD(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{
	omci_onu_g_ptr onu_g_ptr=NULL;
	char buf[13]={0};
	
	if(new_info == NULL ||	new_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}
	
	onu_g_ptr = (omci_onu_g_ptr)(new_info->attributes);
	omci_lib_get_loid_password(buf,OMCI_LOID_PASSWORD_LENS);
	memcpy(onu_g_ptr->logicalPassword, buf, OMCI_LOID_PASSWORD_LENS);
	
	return 0;	
}

int omci_me_onu_g_test_result_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    int ret = 0;
	uint8_t *tmp = NULL;

    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	/*send test result packets*/
	/*ONU test type 1 cmd*/
	tmp = (uint8_t *)(me_info->attributes);
	*tmp = 1;
	put16(tmp+1, 0x1111);
	/*ONU test type 2 cmd*/
	tmp = tmp + 3;
	*tmp = 2;
	put16(tmp+1, 0x2222);		
	/*ONU test type 3 cmd*/
	tmp = tmp + 3;
	*tmp = 3;
	put16(tmp+1, 0x3333);	
	/*ONU test type 4 cmd*/
	tmp = tmp + 3;
	*tmp = 4;
	put16(tmp+1, 0x4444);
	/*ONU test type 5cmd*/
	tmp = tmp + 3;
	*tmp = 5;
	put16(tmp+1, 0x5555);
	/*ONU test type 6 cmd*/
	tmp = tmp + 3;
	*tmp = 6;
	put16(tmp+1, 0x6666);		
	/*ONU test type 7 cmd*/
	tmp = tmp + 3;
	*tmp = 7;
	put16(tmp+1, 0x7777);	
	/*ONU test type 8 cmd*/
	tmp = tmp + 3;
	*tmp = 8;
	put16(tmp+1, 0x8888);
	/*ONU test type 9 cmd*/
	tmp = tmp + 3;
	*tmp = 9;
	put16(tmp+1, 0x9999);	
	/*ONU test type 10 cmd*/
	tmp = tmp + 3;
	*tmp = 10;
	put16(tmp+1, 0xaaaa);	

	if(me_info->dev_id == OMCI_EXTENED_MSG){
		me_info->attr_len = 30; //10 * 3 bytes
	}	

	omci_adpt_report_event(OMCI_EVENT_TEST_RESULT,me_info);
	ret = 0;
end:
    return ret;
}

int onu_g_test_support(omci_me_info_ptr me_info)
{
    int ret = OMCI_CMD_SUCCESS;

	if(me_info == NULL)
		return OMCI_CMD_ERROR;
	
    if(me_info->attributes[0] <= 0x6){
        ret = OMCI_CMD_NOT_SUPPORT;
    }

    return ret;
}

//9.1.2 ONU2-G
int getOMCCVersionValue(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{
	omci_onu2_g_ptr onu2_g_info=NULL;

	if(new_info == NULL ||	new_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}

	onu2_g_info = (omci_onu2_g_ptr)(new_info->attributes);
	onu2_g_info->omccVersion= omci_onu_cap_g.omccVersion;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s] The omccVersion = %d\n",__FUNCTION__,onu2_g_info->omccVersion);

	return 0;
}

int getSysUpTimeValue(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{
	omci_onu2_g_ptr onu2_g_info=NULL;
	FILE *fp = NULL;
	float timeSec = 0.0;
	uint32_t sysUpTime = 0;

	if(new_info == NULL ||	new_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}

	if ((fp = fopen("/proc/uptime", "r")) == NULL)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] open /proc/uptime fail\n",__FUNCTION__);
		return -1;
	}

	if(fscanf(fp, "%f", &timeSec) == EOF)
	{
		fclose(fp);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] fscanf return EOF\n",__FUNCTION__);
		return -1;
	}
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"timeSec = %f\n", timeSec);
	sysUpTime = (uint32_t)(timeSec * 100); /*10 ms interval*/
	fclose(fp);

	onu2_g_info = (omci_onu2_g_ptr)(new_info->attributes);	
	onu2_g_info->sysUpTime = sysUpTime;

	return 0;
}

int setSecurityModeValue(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{			
#ifndef BSP_BUILD
	omci_onu2_g_ptr onu2_g_info=NULL;
	uint8_t modeEnable = 0 ;
	char buffer[25] ={0};

	if(new_info == NULL ||	new_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}

	onu2_g_info = (omci_onu2_g_ptr)(new_info->attributes);	
	if (onu2_g_info->securityMode == 1)
		modeEnable = 1;
	else
		modeEnable = 0;

	/*CFG Manager function "gponOnuCmdSetAttrFunc" without configuration for "SecurityMode" Now!!!*/
	sprintf(buffer, "%x", modeEnable);
	omci_adpt_set_commit_attriubte("GPON_ONU", "SecurityMode", buffer);
#else
	/*See CFG Manager function gponOnuCmdSetAttrFunc(), Attribute 'SecurityMode' do nothing!*/
#endif	

	return 0;
}

//9.1.3 ONU data

// 9.1.12 ONU remote debug
int setRemoteDebugCmd(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{
	int status=0;
	char cmd_buff[26]={0};
	char test_cmd[128]={0};
	omci_onu_remote_debug_ptr onu_remote_debug_attr = NULL;

	if(new_info == NULL ||	new_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}
	onu_remote_debug_attr = (omci_onu_remote_debug_ptr)new_info->attributes;
	memcpy(cmd_buff, onu_remote_debug_attr->command, 25);

	sprintf(test_cmd, "echo %s > /tmp/omci_debug_reply_table.txt",cmd_buff);
	if((status = system(test_cmd)) < 0)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"[%s] fail!\n",__FUNCTION__);
		return -1;
	}
	else
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s] success!\n",__FUNCTION__);
	}
	return 0;
}

int getRemoteDebugReplyTab(omci_me_info_ptr new_info,omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	FILE *fp=NULL;	
	char *tableBuffer = NULL;
	long filesize=0;

	omci_onu_remote_debug_ptr onu_remote_debug_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == new_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
		return -1;
    }
	onu_remote_debug_attr = (omci_onu_remote_debug_ptr)new_info->attributes;
    if(onu_remote_debug_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
		return -1;
    }
	
	fp = fopen("/tmp/omci_debug_reply_table.txt", "r");
	if(fp == NULL)
	{
		return -1;
	}
	else
	{
		/*1.calculate the table size*/
		fseek(fp, 0, SEEK_END);
		filesize = ftell(fp);
		if(filesize <= 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"%s [%d]:---filesize = %ld\n",__FUNCTION__,__LINE__,filesize);
			ret = -1;
			goto end;
		}
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"%s [%d]:---filesize = %ld\n",__FUNCTION__,__LINE__,filesize);

		if(onu_remote_debug_attr->replyTable.len < filesize){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->attribute table size is not enough, failure\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
		/*2.malloc memory for table*/
		tableBuffer =  onu_remote_debug_attr->replyTable.buf;	
		if(tableBuffer == NULL)
		{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"%s [%d]:---malloc fail!!\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
		memset(tableBuffer,0, filesize);
		
		/*3.get  the table copy */
		fseek(fp, 0, SEEK_SET);
		onu_remote_debug_attr->replyTable.len = fread(tableBuffer, filesize, sizeof(char),fp);
	}

//	omciDumpTable(tableBuffer, filesize);

	ret = 0;
end:
	fclose(fp);
	return ret;
	
}


